{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Regression Test Example Using ObservablesTestCase Class"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This demonstrates using the ObservablesTestCase class through cantera that can compare between two version of a model.  It is expected to also compare against experimental data in the future (currently not implemented)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from rmgpy.tools.observablesRegression import ObservablesTestCase\n",
    "from IPython.display import display, Image\n",
    "from rmgpy.species import Species"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Set up reactor conditions \n",
    "ethane=Species().fromSMILES('CC')\n",
    "argon=Species().fromSMILES('[Ar]')\n",
    "methyl=Species().fromSMILES('[CH3]')\n",
    "\n",
    "reactorTypeList = ['IdealGasReactor']\n",
    "molFracList=[{ethane: 0.05, argon: 0.95}]\n",
    "Plist=([3],'atm')\n",
    "Tlist=([1500,1750,2000],'K')\n",
    "terminationTime = ([5e-5],'s')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Set the observables that we care about\n",
    "observables = {'species':[ethane, methyl]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Create observables test case and compare the old and new models\n",
    "\n",
    "minimal = ObservablesTestCase(title = 'Ethane Pyrolysis',\n",
    "                              oldDir = 'data/regression/old',\n",
    "                              newDir = 'data/regression/new',\n",
    "                              observables = observables,\n",
    "                              #ck2cti = False,  # Set to false means we use RMG's internal conversion to Cantera objects\n",
    "                                              # rather than using cantera's ck2cti parser on the chemkin file.\n",
    "                             )\n",
    "\n",
    "minimal.generateConditions(reactorTypeList = reactorTypeList,\n",
    "                           reactionTimeList = terminationTime,\n",
    "                           molFracList = molFracList,\n",
    "                           Tlist = Tlist,\n",
    "                           Plist = Plist)\n",
    "\n",
    "variablesFailed = minimal.compare(tol=0.05, plot = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Display the plots for the conditions\n",
    "observableSpecies = observables['species']\n",
    "for i in range(len(minimal.conditions)):\n",
    "    for j in range(len(observables['species'])):\n",
    "        conditionIndex = i+1\n",
    "        speciesLabel = observableSpecies[j].molecule[0].toSMILES()\n",
    "        print 'Plotting condition {0} comparison for species {1}'.format(conditionIndex, speciesLabel)\n",
    "        display(Image(filename=\"condition_{0}_species_{1}.png\".format(conditionIndex, speciesLabel)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
